var e = require;
var t = module;
var o = exports;
Object.defineProperty(o, "__esModule", {value: !0}), (o.EventManager = void 0);
var n = (function () {
    function e() {
        this._eventListeners = {};
    }
    return (
        (e.getInstance = function () {
            return this.instance || (this.instance = new e()), this.instance;
        }),
        (e.destroy = function () {
            this.instance && (delete this.instance, (this.instance = null));
        }),
        (e.prototype.getEventListenersIndex = function (e, t, o) {
            for (var n = -1, a = 0; a < this._eventListeners[e].length; a++) {
                var i = this._eventListeners[e][a];
                if (i.callBack == t && (!o || i.target == o)) {
                    n = a;
                    break;
                }
            }
            return n;
        }),
        (e.prototype.addEventListener = function (e, t, o) {
            if (e) {
                if (null == t) return cc.log("addEventListener callBack is nil"), !1;
                var n = {callBack: t, target: o};
                return (
                    null == this._eventListeners[e]
                        ? (this._eventListeners[e] = [n])
                        : -1 == this.getEventListenersIndex(e, t, o) && this._eventListeners[e].push(n),
                    !0
                );
            }
            cc.warn("eventName is empty" + e);
        }),
        (e.prototype.setEventListener = function (e, t, o) {
            if (e) {
                if (null == t) return cc.log("setEventListener callBack is nil"), !1;
                var n = {callBack: t, target: o};
                return (this._eventListeners[e] = [n]), !0;
            }
            cc.warn("eventName is empty" + e);
        }),
        (e.prototype.removeEventListener = function (e, t, o) {
            if (null != this._eventListeners[e]) {
                var n = this.getEventListenersIndex(e, t, o);
                -1 != n && this._eventListeners[e].splice(n, 1);
            }
        }),
        (e.prototype.raiseEvent = function (e, t) {
            if (null != this._eventListeners[e]) {
                for (var o = [], n = 0, a = this._eventListeners[e]; n < a.length; n++) {
                    var i = a[n];
                    o.push({callBack: i.callBack, target: i.target});
                }
                for (var r = 0, s = o; r < s.length; r++) (i = s[r]).callBack.call(i.target, e, t);
            }
        }),
        (e.instance = null),
        e
    );
})();
o.EventManager = n.getInstance();
